package com.qf.Servlet.Impl;

import com.qf.Servlet.UserService;
import com.qf.dao.Userdao;
import com.qf.dao.UserdaoImpl.UserdaoImpl;
import com.qf.pojo.Profile;
import com.qf.pojo.User;
import com.qf.utils.Constants;
import com.qf.utils.MD5Utils;

import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project web人员管理系统
 * @Package com.qf.Servlet.Impl
 * @Description:
 * @Date 2022/5/27 12:36
 */
public class UserServiceImpl  implements UserService {
    @Override
    public User login(String name, String password) {
        UserdaoImpl userdao = new UserdaoImpl();
        User login = userdao.login(name);
         if(login==null){
             return  null;
         }
         if(!Constants.USER_ACTIVE.equals(login.getStatus())){
             return  null;
         }
        String md5 = MD5Utils.md5(password);
         if(login.getPassword().equals(md5)){
             return  login;
         }
        return null;
    }

    @Override
    public boolean checkduUser(String name) {
        UserdaoImpl userdao = new UserdaoImpl();
        User login = userdao.login(name);
        if(login==null){
            return  true;
        }else {
            return false;
        }

    }

    @Override
    public int AddUser(User user) {
        String md5 = MD5Utils.md5(user.getPassword());
        user.setPassword(md5);
        user.setStatus(Constants.USER_ACTIVE);
        UserdaoImpl userdao = new UserdaoImpl();
        int i = userdao.addUser(user);
        return i;


    }

    @Override
    public List<Profile> all() {
        UserdaoImpl userdao = new UserdaoImpl();
        List<Profile> all = userdao.all();

        return  all;
    }

    @Override
    public int delect(Integer id) {
        UserdaoImpl userdao = new UserdaoImpl();
        int delect = userdao.delect(id);

        return delect;
    }

    @Override
    public User yonghu(String name) {
        UserdaoImpl userdao = new UserdaoImpl();
        User login = userdao.login(name);

        return login;
    }

    @Override
    public Profile logins(String name) {
        UserdaoImpl userdao = new UserdaoImpl();
        Profile logins = userdao.logins(name);

        return logins;
    }


}
